package com.zrwl.poscloud.core.restapi.file;

import com.zrwl.poscloud.base.entity.IpAuth;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.vo.PageResult;
import com.zrwl.poscloud.xo.service.AccessManageService;
import com.zrwl.poscloud.xo.vo.FileAccessVO;
import com.zrwl.poscloud.xo.vo.IpAuthVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/accessManageApi")
public class AccessManageApi {

    @Autowired
    AccessManageService accessManageService;

    /***
     * 获取访问统计信息
     * @return
     */
    @RequestMapping("/getAccessList")
    public String getAccessList(FileAccessVO fileAccessVO) {
        PageResult result =accessManageService.getFileAccessList(fileAccessVO);
        return ResultUtil.successWithData(result);
    }
    /***
     * 创建IP授权信息
     * type 1:允许访问，2：禁止访问，后来者优先
     * @return
     */
    @RequestMapping("/addIpAuth")
    public String addIpAuth(IpAuthVO authVO) {
        IpAuth entity=new IpAuth();
        BeanUtils.copyProperties(authVO,entity);
        entity.insert();
        return ResultUtil.successWithMessage("创建成功");
    }
    /***
     * 创建IP授权信息
     * type 1:允许访问，2：禁止访问，后来者优先
     * @return
     */
    @RequestMapping("/deleteIpAuth")
    public String deleteIpAuth(IpAuthVO authVO) {
        IpAuth entity=new IpAuth();
        entity.deleteById(authVO.getUid());
        return ResultUtil.successWithMessage("删除成功");
    }
}


